﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WF_Business;
using ExtBusiness;

public partial class GenerateCode_UserInfoSpResult : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strId = Request.Params["sid"];
            string strResult = Request.Params["resultFlag"];
            UpdateUserFlag(strId, strResult);
        }
    }

    /// <summary>
    /// 审批通过注册用户
    /// </summary>
    /// <param name="strSysId">申报用户id</param>
    /// <param name="strResult">操作标志位</param>
    private void UpdateUserFlag(string strSysId, string strResult)
    {
        try
        {
            string sql= string.Empty;

            if (strResult.CompareTo("1") == 0)//通过
            {
                //对于地图审核默认设置其状态为已办理权限（以后可以去掉）
                string strType = ConfigurationManager.AppSettings["bsqxspSystemFlag"];

                sql = string.Format(@"update sys_user t set ISVALID='1',is_promise=1,CAN_SYNC=1,type='{1}' where ID='{0}' ",
                    strSysId,strType);
                SysParams.OAConnection().RunSql(sql);

                //获取用户信息
                sql = string.Format(@"select userid,username,MOBILE from sys_user where id = '{0}'", strSysId);

                DataTable dtReturn = new DataTable();
                SysParams.OAConnection().RunSql(sql, out dtReturn);
                string strUserName = "", strMobile = "", strUserID = "";
                if (dtReturn.Rows.Count > 0)
                {
                    strUserName = dtReturn.Rows[0]["username"].ToString();
                    strMobile = dtReturn.Rows[0]["mobile"].ToString();
                    strUserID = dtReturn.Rows[0]["userid"].ToString(); //添加用户ID 
                }

                //获取消息内容
                string strStepMsg = "", strStepN0 = "";
                sql = string.Format(@"select step_msg,step_no from xt_request_step where step_name='用户注册'",strSysId);
                SysParams.OAConnection().RunSql(sql, out dtReturn);
                if (dtReturn.Rows.Count > 0)
                {
                    strStepMsg = dtReturn.Rows[0]["step_msg"].ToString();
                    //获取信息步骤码
                    strStepN0 = dtReturn.Rows[0]["step_no"].ToString();
                }

                //当消息内容设置为空时，将不再发送消息。
                if (!string.IsNullOrEmpty(strStepMsg))
                {
                    //整理消息内容:strStepMsg中{0}:代表用户名称;{1}:代表事项名称; 
                    try
                    {
                        strStepMsg = string.Format(strStepMsg, strUserName);
                    }
                    catch { }
                    
                    //{0},您好，您的{2}业务申报权限已被审批通过
                    sql = string.Format(@"Insert into xt_messagebox(MESSAGETEXT,PHONENO,USERNAME,USERID)  values ('{2}','{1}','{0}','{3}')",
                        strUserName, strMobile, strStepMsg, strUserID);
                    SysParams.OAConnection().RunSql(sql);

                }
            }
            else
            {
                sql = string.Format(@"delete from sys_user where ID='{0}' ", strSysId); ;
                SysParams.OAConnection().RunSql(sql);
            }

            //保存短信信息

            string strScript = "<script>this.location = 'WyUserIdGenerate.aspx';</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptBack", strScript);
        }
        catch (Exception e)
        {
            Common.WindowAppear.WriteAlert(Page, e.Message);
        }
    }
}
